package cn.tedu.ivos2.user.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.base.response.StatusCode;
import cn.tedu.ivos2.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos2.user.pojo.dto.UserQuery;
import cn.tedu.ivos2.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos2.user.pojo.entity.User;
import cn.tedu.ivos2.user.pojo.vo.UserVO;
import cn.tedu.ivos2.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;// 注意：此处注入的是接口，实际上使用的是接口的实现类，这是多态用法！
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录参数：{}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);// Ctrl + Alt 点击方法名去实现类
        return new JsonResult(StatusCode.LOGIN_SUCCESS,userVO);
    }
    @PostMapping("save")
    public JsonResult save(UserSaveParam userSaveParam){
        userService.save(userSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("list")
    public JsonResult list(UserQuery userQuery){
        List<UserVO> list = userService.list(userQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("update/password/{id}")
    public JsonResult updatePassword(@PathVariable Long id){
        userService.updatePassword(id);
        return JsonResult.ok();
    }
    @PostMapping("update/status/{id}/{status}")
    public JsonResult updateStatus(@PathVariable Long id, @PathVariable String status){
        userService.updateStatus(id,status);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        userService.delete(id);
        return JsonResult.ok();
    }
    @GetMapping("query/audit/{id}")
    public JsonResult queryAudit(@PathVariable Long id){
        List<UserVO> list = userService.queryAudit(id);
        return JsonResult.ok(list);
    }

}
